﻿using System;
using System.Collections.Generic;
using System.Linq.Expressions;

namespace SimpleOrmCFPC.Core.Query.expressions
{
    public static class ExpressionNodeTypeHelper
    {
        private static readonly Dictionary<ExpressionType, String> SqlOperatorsMap = new Dictionary
            <ExpressionType, string>
            {
                {ExpressionType.GreaterThan, ">"},
                {ExpressionType.GreaterThanOrEqual, ">="},
                {ExpressionType.Equal, "="},
                {ExpressionType.LessThan, "<"},
                {ExpressionType.LessThanOrEqual, "<="},
                {ExpressionType.AndAlso, "and"},
                {ExpressionType.And, "and"},
                {ExpressionType.Or, "or"},
                {ExpressionType.OrElse, "or"},
                {ExpressionType.NotEqual, "!="},
            };

        public static String ConvertToSqlOperator(this ExpressionType expressionType)
        {
            if (!SqlOperatorsMap.ContainsKey(expressionType))
                throw new NotSupportedException("Operator not supported : " + expressionType);
            return SqlOperatorsMap[expressionType];
        }
    }
}